﻿using System;
using System.Collections.Generic;

namespace Kiva7.DataClasses
{
    public class CombinedPaymentsDictionary : Dictionary<DateTime, CombinedPayments>
    {
        public void AddScheduledPayments(ScheduledPaymentList list)
        {
            foreach(ScheduledPayment payment in list)
            {
                if (payment.DueDate.HasValue)
                {
                    CombinedPayments combined;
                    DateTime date = new DateTime(payment.DueDate.Value.Year, payment.DueDate.Value.Month, 1);
                    if (ContainsKey(date))
                    {
                        combined = this[date];
                    }
                    else
                    {
                        combined = new CombinedPayments();
                        combined.Date = date;
                        Add(date, combined);
                    }
                    combined.Scheduled += payment.Amount;
                }
            }
        }

        public void AddPayments(PaymentList list)
        {
            foreach (Payment payment in list)
            {
                if (payment.ProcessedDate.HasValue)
                {
                    CombinedPayments combined;
                    DateTime date = new DateTime(payment.ProcessedDate.Value.Year, payment.ProcessedDate.Value.Month, 1);
                    if (ContainsKey(date))
                    {
                        combined = this[date];
                    }
                    else
                    {
                        combined = new CombinedPayments();
                        combined.Date = date;
                        Add(date, combined);
                    }
                    combined.Actual += payment.Amount;
                }
            }
        }

    }
}
